<?php

namespace app\admin\controller;

use think\Request;

class Index extends Base
{
    protected $service;
    protected $operator_id;
    public function __construct(Request $request)
    {
        $this->request = $request;
        $this->service = new \app\admin\service\Index();
        $this->operator_id = $request->operator_id;
    }

    /**
     * @describe 订单排行榜
     * @author: Bobo
     * @date: 2025-09-10 15:17:53
     * @param [type] @required
     * @return Renderable
     */
    public function OrderRanking()
    {

        $params = empty($this->request->params) ? [] : $this->request->params;

        $time_period    = isset($params['time_period'])        ? intval($params['time_period'])        : 1;

        $res = $this->service->OrderRanking($time_period, $this->operator_id);
        $code = $res['code'];
        $data = $res['data'] ?? [];
        $message = $res['message'] ?? "";
        return $this->returnJsonData($code, $data, $message);
    }

    /**
     * @describe 订单统计
     * @author: Bobo
     * @date: 2025-09-10 15:49:13
     * @param [type] @required
     * @return Renderable
     */
    public function OrderStatistics()
    {
        $res = $this->service->OrderStatistics();
        $code = $res['code'];
        $data = $res['data'] ?? [];
        $message = $res['message'] ?? "";
        return $this->returnJsonData($code, $data, $message);
    }

    /**
     * @describe 待办列表
     * @author: Bobo
     * @date: 2025-09-10 15:49:13
     * @param [type] @required
     * @return Renderable
     */
    public function ToDo()
    {
        $pageIndex         = isset($this->request->params['pageIndex'])             ? intval($this->request->params['pageIndex'])             : 1;
        $pageSize          = isset($this->request->params['pageSize'])              ? intval($this->request->params['pageSize'])              : 10;

        $res = $this->service->ToDo($this->operator_id, $pageIndex, $pageSize);
        $code = $res['code'];
        $data = $res['data'] ?? [];
        $message = $res['message'] ?? "";
        return $this->returnJsonData($code, $data, $message);
    }

    /**
     * @describe 已发起列表
     * @author: Bobo
     * @date: 2025-09-11 10:20:50
     * @param int $pageIndex 页码
     * @param int $pageSize 每页条数
     * @return Renderable
     */
    public function Initiated()
    {
        $pageIndex         = isset($this->request->params['pageIndex'])             ? intval($this->request->params['pageIndex'])             : 1;
        $pageSize          = isset($this->request->params['pageSize'])              ? intval($this->request->params['pageSize'])              : 10;

        $res = $this->service->Initiated($this->operator_id, $pageIndex, $pageSize);
        $code = $res['code'];
        $data = $res['data'] ?? [];
        $message = $res['message'] ?? "";
        return $this->returnJsonData($code, $data, $message);
    }

    /**
     * @describe 已发起处理结果
     * @author: Bobo
     * @date: 2025-09-11 10:20:50
     * @param int $id 业务日志id
     * @return Renderable
     */
    public function InitiatedProcessedResult($id)
    {
        $res = $this->service->InitiatedProcessedResult($id);
        return $this->returnJsonData($res['code'], $res['data'], $res['message']);
    }
}
